From 4262a4586e1a1188f549bf044e6d7e9bb2b50bd9 Mon Sep 17 00:00:00 2001 From: robertl Date: Sun, 22 Jul 2007 22:52:54 +0000 Subject: [PATCH] Andy adds polish to WBT module, adds doc for TK1. --- vecs.c | 12 ++++-- wbt-200.c | 88 +++++++++++++++++++------------------- xmldoc/formats/wbt-tk1.xml | 11 +++++ 3 files changed, 63 insertions(+), 48 deletions(-) create mode 100644 xmldoc/formats/wbt-tk1.xml diff --git a/vecs.c b/vecs.c index 7819af044..f71bd0822 100644 --- a/vecs.c +++ b/vecs.c @@ -398,13 +398,19 @@ vecs_t vec_list[] = { &wbt_svecs, "wbt", "Wintec WBT-100/200 GPS Download", - "bin" + NULL }, { &wbt_fvecs, "wbt-bin", - "Wintec WBT-100/200 Binary file format", - NULL + "Wintec WBT-100/200 Binary File Format", + "bin" + }, + { + &wbt_fvecs, + "wbt-tk1", + "Wintec WBT-201/G-Rays 2 Binary File Format", + "tk1" }, { &hiketech_vecs, diff --git a/wbt-200.c b/wbt-200.c index ce9688c25..1acbe2448 100644 --- a/wbt-200.c +++ b/wbt-200.c @@ -83,20 +83,9 @@ static struct { #define RETRIES 60 /* - A conversation looks like this - - >> $PFST,FIRMWAREVERSION - << $PFST,FIRMWAREVERSION,WBT200,3,31,6090,R2*77 - >> $PFST,NORMAL - << $PFST,NORMAL,*02 - >> $PFST,READLOGGER - << $PFST,READLOGGER,*17 - << 0xFFFF, , 0xFFFF - << (length + 1) * 12 or 16 bytes of data - << ==== - >> $PFST,NORMAL - << $PFST,NORMAL,*02 -*/ + * For WBT-200 protocol documentation see: + * http://hexten.net/wiki/index.php/WBT-200_Comms_Protocol + */ static void *fd; static FILE *fl; @@ -133,7 +122,7 @@ struct buf_head { }; struct read_state { - route_head *route_head; + route_head *route_head; unsigned wpn, tpn; struct buf_head data; @@ -406,7 +395,10 @@ static void file_deinit(void) { } static int starts_with(const char *buf, const char *pat) { - return memcmp(buf, pat, strlen(pat)) == 0; + size_t pat_len = strlen(pat); + return (pat_len <= strlen(buf)) + ? (memcmp(buf, pat, pat_len) == 0) + : 0; } /* Send a command then wait for a line starting with the command string @@ -496,16 +488,16 @@ static int check_date(gbuint32 tim) { static waypoint *make_point(double lat, double lon, double alt, time_t tim, const char *fmt, int index) { char wp_name[20]; - waypoint *wpt = waypt_new(); + waypoint *wpt = waypt_new(); - sprintf(wp_name, fmt, index); + sprintf(wp_name, fmt, index); - wpt->latitude = lat;; - wpt->longitude = lon; - wpt->altitude = alt; - wpt->creation_time = tim; - wpt->shortname = xstrdup(wp_name); - + wpt->latitude = lat;; + wpt->longitude = lon; + wpt->altitude = alt; + wpt->creation_time = tim; + wpt->shortname = xstrdup(wp_name); + return wpt; } @@ -521,8 +513,8 @@ static int wbt200_data_chunk(struct read_state *st, const void *buf, int fmt) { gbuint32 tim; double lat, lon, alt; time_t rtim; - waypoint *tpt = NULL; - const char *bp = buf; + waypoint *tpt = NULL; + const char *bp = buf; size_t buf_used = fmt_version[fmt].reclen; tim = le_read32(bp + 0); @@ -552,13 +544,13 @@ static int wbt200_data_chunk(struct read_state *st, const void *buf, int fmt) { tpt = make_trackpoint(st, lat, lon, alt, rtim); - if (NULL == st->route_head) { - db(1, "New Track\n"); - st->route_head = route_head_alloc(); - track_add_head(st->route_head); - } + if (NULL == st->route_head) { + db(1, "New Track\n"); + st->route_head = route_head_alloc(); + track_add_head(st->route_head); + } - track_add_wpt(st->route_head, tpt); + track_add_wpt(st->route_head, tpt); return 1; } @@ -746,7 +738,7 @@ static int wbt201_data_chunk(struct read_state *st, const void *buf) { double lat, lon, alt; time_t rtim; waypoint *tpt = NULL; - const char *bp = buf; + const char *bp = buf; /* Zero records are skipped */ if (all_null(buf, RECLEN_WBT201)) { @@ -779,13 +771,13 @@ static int wbt201_data_chunk(struct read_state *st, const void *buf) { tpt = make_trackpoint(st, lat, lon, alt, rtim); - if (NULL == st->route_head) { - db(1, "New Track\n"); - st->route_head = route_head_alloc(); - track_add_head(st->route_head); - } + if (NULL == st->route_head) { + db(1, "New Track\n"); + st->route_head = route_head_alloc(); + track_add_head(st->route_head); + } - track_add_wpt(st->route_head, tpt); + track_add_wpt(st->route_head, tpt); } return 1; @@ -796,12 +788,10 @@ static void wbt201_process_chunk(struct read_state *st) { db(2, "Processing %lu bytes of data\n", st->data.used); - do { - size_t got = buf_read(&st->data, buf, sizeof(buf)); - if (got != sizeof(buf)) { - break; - } - } while (wbt201_data_chunk(st, buf)); + while (buf_read(&st->data, buf, sizeof(buf)) == sizeof(buf) + && wbt201_data_chunk(st, buf)) { + /* do nothing */ + } } static int wbt201_read_chunk(struct read_state *st, unsigned pos, unsigned limit) { @@ -937,6 +927,10 @@ static void file_read(void) { fatal(MYNAME ": Read error\n"); } + /* Although wbt-tk1 and wbt-bin are enumerated as distinct formats + * we handle them both here and autodetect which type we have. + */ + /* WBT201 TK1 format? */ buf_rewind(&st.data); @@ -985,6 +979,8 @@ static void data_read(void) { } } +/* wbt */ + static arglist_t wbt_sargs[] = { { "erase", &erase, "Erase device data after download", "0", ARGTYPE_BOOL, ARG_NOMINMAX }, @@ -1005,6 +1001,8 @@ ff_vecs_t wbt_svecs = { CET_CHARSET_UTF8, 1 /* master process: don't convert anything | CET-REVIEW */ }; +/* used for wbt-bin /and/ wbt-tk1 */ + static arglist_t wbt_fargs[] = { ARG_TERMINATOR }; diff --git a/xmldoc/formats/wbt-tk1.xml b/xmldoc/formats/wbt-tk1.xml new file mode 100644 index 000000000..4fba4bca0 --- /dev/null +++ b/xmldoc/formats/wbt-tk1.xml @@ -0,0 +1,11 @@ +File protocol for the Wintec WBT-201 / G-Rays 2 +GPS data logger. This format reads the binary file format created +by Wintec's Time Machine X application. + +Wintec WBT-201 + + + Command showing conversion of a Wintec binary file to GPX + gpsbabel -w -t -i wbt-tk1 -f tracks.tk1 -o gpx -F out.gpx + + -- 2.30.2